package com.rd.student.jike.class2.lihongming.week724_730.S728;

import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @Auther:Heinrich
 * @Date:2023/7/28-07-28-22:42
 * @Description:com.rd.student.jike.class2.lihongming.week724_730.S728
 * @version:1.0
 */
public class Module5 {
    public static void main(String[] args)throws Exception {
        Scanner scanner = new Scanner(System.in);
        LinkedList<String> list = randomName(scanner.nextInt());
        System.out.println(list);
        File file = new File("random.txt");
        OutputStream os = new FileOutputStream(file,true);
        for (String s : list) {
            String content = s + "、";
            byte[] byteArr = content.getBytes();
            os.write(byteArr);
        }
        os.close();

    }
    public static LinkedList<String> randomName(int n) throws Exception{
        File file1 = new File("random.txt");
        InputStream is1 = new FileInputStream(file1);
        byte[] byte1 = new byte[(int) file1.length()];
        is1.read(byte1);
        LinkedList<String> randomPass = new LinkedList<>();
        String passName = new String(byte1);
        int a=0,b;
        for (int i = 0; i < passName.length(); i++) {
            if(passName.charAt(i)=='、'){
                b=i;
                String name = passName.substring(a,b);
                a=i+1;
                randomPass.add(name);
            }
        }
       //randomPass = LinkedList<String>(Arrays.asList(passName.split("、")));

        a=0;
        b=0;
        File file2 = new File("leave.txt");
        InputStream is2 = new FileInputStream(file2);
        byte[] byte2 = new byte[(int) file2.length()];
        is2.read(byte2);
        String sickName = new String(byte2);
        //System.out.println(sickName);
        for (int i = 0; i < sickName.length(); i++) {
            if(sickName.charAt(i)=='、'){
                b=i;
                String name = sickName.substring(a,b);
                a=i+1;
                randomPass.add(name);
            } else if (i==sickName.length()-1) {
                String name = sickName.substring(a,i+1);
                randomPass.add(name);
            }
        }
        //randomPass = (LinkedList<String>) Arrays.asList(sickName.split("、"));
        //System.out.println(randomPass);
        a=0;
        b=0;
        File file = new File("all.txt");
        InputStream is = new FileInputStream(file);
        byte[] byteArr = new byte[(int) file.length()];
        is.read(byteArr);
        LinkedList arr = new LinkedList();
        String names = new String(byteArr);
        for (int i = 0; i < names.length(); i++) {
            int temp = 0;
            if(names.charAt(i)=='、'){
                b=i;
                String name = names.substring(a,b);
                a=i+1;
                if(randomPass.size()!=0){
                    for (int j = 0; j < randomPass.size(); j++) {
                        if(name.equals(randomPass.get(j))){
                            temp=1;
                        }
                    }
                    if(temp != 1){
                        arr.add(name);
                    }
                }else{
                    arr.add(name);
                }
                //System.out.println(arr);
            }else if (i==names.length()-1) {
                String name = names.substring(a,i+1);
                arr.add(name);
            }
        }
        Collections.shuffle(arr);
        LinkedList<String> list = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            list.add((String) arr.get(i));
        }
        //System.out.println();
        is.close();
        return list;
    }
}
